package com.dkd.music.controller;

import com.dkd.common.annotation.Log;
import com.dkd.common.core.controller.BaseController;
import com.dkd.common.core.domain.AjaxResult;
import com.dkd.common.core.page.TableDataInfo;
import com.dkd.common.enums.BusinessType;
import com.dkd.common.utils.poi.ExcelUtil;
import com.dkd.music.domain.Genre;
import com.dkd.music.service.IGenreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 音乐种类Controller
 * 
 * @author grz
 * @date 2025-10-25
 */
@RestController
@RequestMapping("/music/genre")
public class GenreController extends BaseController
{
    @Autowired
    private IGenreService genreService;

    /**
     * 查询音乐种类列表
     */
    @PreAuthorize("@ss.hasPermi('music:genre:list')")
    @GetMapping("/list")
    public TableDataInfo list(Genre genre)
    {
        startPage();
        List<Genre> list = genreService.selectGenreList(genre);
        return getDataTable(list);
    }

    /**
     * 导出音乐种类列表
     */
    @PreAuthorize("@ss.hasPermi('music:genre:export')")
    @Log(title = "音乐种类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Genre genre)
    {
        List<Genre> list = genreService.selectGenreList(genre);
        ExcelUtil<Genre> util = new ExcelUtil<Genre>(Genre.class);
        util.exportExcel(response, list, "音乐种类数据");
    }

    /**
     * 获取音乐种类详细信息
     */
    @PreAuthorize("@ss.hasPermi('music:genre:query')")
    @GetMapping(value = "/{genreId}")
    public AjaxResult getInfo(@PathVariable("genreId") Long genreId)
    {
        return success(genreService.selectGenreByGenreId(genreId));
    }

    /**
     * 新增音乐种类
     */
    @PreAuthorize("@ss.hasPermi('music:genre:add')")
    @Log(title = "音乐种类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Genre genre)
    {
        return toAjax(genreService.insertGenre(genre));
    }

    /**
     * 修改音乐种类
     */
    @PreAuthorize("@ss.hasPermi('music:genre:edit')")
    @Log(title = "音乐种类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Genre genre)
    {
        return toAjax(genreService.updateGenre(genre));
    }

    /**
     * 删除音乐种类
     */
    @PreAuthorize("@ss.hasPermi('music:genre:remove')")
    @Log(title = "音乐种类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{genreIds}")
    public AjaxResult remove(@PathVariable Long[] genreIds)
    {
        return toAjax(genreService.deleteGenreByGenreIds(genreIds));
    }
}
